
import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Amira
 */
public class Bomb extends Sprite {

    int[] FRAME_SEQUENCE = {0, 1};
    int[] EXPLODE_SEQUENCE = {0, 1, 2, 3, 4};
    boolean Active = false;
    int time = 120;
    int time_explode = 40;
    int p_x;
    int p_y;
    int speed_x;
    int speed_y;

    public Bomb(int x , int y) throws Exception {
        super(Image.createImage("/resource/Bomb.png"), 20, 20);
        setFrameSequence(FRAME_SEQUENCE);
//        p_x = x;
//        p_y = y;
//        speed_x = 20 * x;
//        speed_y = 20 * y + 51;
        setFrame(1);
    }

    public void Activate() throws IOException {
        this.setImage(Image.createImage("/resource/Bomb.png"), 20, 20);
        setFrameSequence(FRAME_SEQUENCE);
        Active = true;
        time = 120;
        time_explode = 40;
        setFrame(1);
    }

    public void move() throws IOException {
        if (Active) {

            time--;
            if (time <= 0) {
                //Explore code here
                System.out.println("Explodeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
                explode();
                move_explode();
            } else {
                nextFrame();

            }
            //if(getFrame() == 2)
            //setFrame(1);
        } else {
            setFrame(1);
        }
    }

    public void explode() throws IOException {
        if (time == 0) {
            this.setImage(Image.createImage("/resource/Bomb-Explode.png"), 20, 20);
            setFrameSequence(EXPLODE_SEQUENCE);
        }
//        time_explode=4;
        // setFrame(0);
    }

    public void move_explode() {

        if (Active) {
            time_explode--;
            System.out.println("not active"
                    + time_explode);
            if (time_explode == 0) {
                System.out.println("not active");
                Active = false;
                this.setVisible(false);
            }

            nextFrame();

        } else {
            setFrame(1);
        }

    }
}
